<#include "../head.html">
<meta charset="utf-8">
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form class="form-horizontal m-t" id="from" method="post">
                       		<input type="hidden" id="id" name="id" value="${dic.id!}">
                       		<input type="hidden" id="pid" name="pid" value="${dic.pid!}">
                       		<input type="hidden" id="state" name="state" value="${dic.state!}">
                            <div class="form-group">
                                <label class="col-sm-3 control-label username">字典名：</label>
                                <div class="col-sm-8">
                                    <input id="name" name="name" class="form-control" type="text" value="${dic.name!}" placeholder="字典名称">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">字典描述：</label>
                                <div class="col-sm-8">
                                    <input id="description" name="description" class="form-control" type="text" value="${dic.description!}"  placeholder="字典描述">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">排序：</label>
                                <div class="col-sm-8">
                                    <input id="sort" name="sort" class="form-control" type="text" value="${dic.sort!}"  placeholder="字典排序">
                                </div>
                            </div>
                             <div class="form-group">
	                            <label class="col-sm-3 control-label" >字典码：</label> 
                                <div class="col-sm-8">
                                    <input id="code" name="code" class="form-control" type="text"value="${dic.code!}"  placeholder="字典码">
                                </div>
                        	</div>
                        	
                            <div class="form-group text-center">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <button class="btn btn-primary" id="btn"><#if dic.state==1>添加<#else>修改</#if></button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

<#include "../foot.html">
<script src="${request.contextPath}/static/js/common.js"></script>
<script type="text/javascript">

//字典码验证
jQuery.validator.addMethod("code", function(value, element) { 
	var password = /^[a-zA-Z0-9]{5,10}$/ ;
	return this.optional(element) || password.test(value); 
	}, "字典码只能是数字或字母5-10位"); 
	
//排序字段验证
jQuery.validator.addMethod("sort", function(value, element) { 
	var password = /^[0-9]{1,2}$/ ;
	return this.optional(element) || password.test(value); 
	}, "字典码只能是数字1-2位"); 
	
$("#from").validate({
	rules: {
		name: {
			required: true,
			maxlength: 10,
		},
		code: {
			required: true,
			maxlength: 10,
			code: true
		},
		sort: {
			required: true,
			maxlength: 2,
			sort: true
		}
	},
	messages: {
		name: {
			required: "请输入字典名",
			maxlength: "名字长度不能大于10位",
			remote:"用户名已经被注册"
		},
		code: {
			required: "请填写字典码"
		},
		sort: {
			required: "请写排序字段"
		}
	},submitHandler: function(form) { 
		$("#btn").attr("disabled","true");
		$(form).ajaxSubmit({
			type:"POST",
			url:BaseUrl+"/manger/dic/edit",
	        data:$(form).serialize(),
	        success:function( data ){
	        	var bool=stateUtil(data);
	        	if(bool){
	        		window.parent.location.reload();
	        	}else{
	        		$("#btn").removeAttr("disabled");
	        	}
	        }
		});
	}, 
	errorPlacement : function(error, element) {//error为错误提示对象，element为出错的组件对象  
     	if (element.attr("name")==="roleId"){  //名字为 roleId 的错误提示重新定位
            	error.css("display","block").appendTo($("#roleId_tip")) ;  
          	}else{  
            	element.after(error) ;//默认是加在 输入框的后面。这个else必须写。不然其他非radio的组件 就无法显示错误信息了。  
      	}  
   } 
});
</script>